package com.datastructure.test.dynamic.jumpingsteps;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class JumpingSteps {

    int sum = 0;
    public static void main(String[] args) {
        JumpingSteps jumpingSteps = new JumpingSteps();
        int[] data = {2,1,4,5,1,2};
        System.out.println(jumpingSteps.findDisappearedNumbers(data));
    }

    public int jumpFloor(int target) {
        int start = 0;
        getResult(start+1,target);
        getResult(start+2,target);
        return sum;
    }

    public void getResult(int start,int target){
        if(start==target||start==(target+1)){
            sum++;
            return;
        }
        getResult(start+1,target);
        getResult(start+2,target);
    }

    public ArrayList<Integer> sortedArray (ArrayList<Integer> nums) {
        // write code here
        List<Integer> collect = nums.stream().map(num -> num * num).sorted().collect(Collectors.toList());
        return (ArrayList<Integer>)collect;
    }

    public boolean poweroftwo (int n) {
        // write code here
        if (0 == n) {
            return false;
        }
        return n == (n & (~n + 2));
//        if(n<=0){
//            return false;
//        }
//        if(n==1){
//            return true;
//        }
//        return powerOfTwo(n/2,n % 2);
    }

    private boolean powerOfTwo(int quotient, int remainder) {
        if(quotient==1&&remainder==0){
            return true;
        }
        if(quotient==0&&remainder!=0){
            return false;
        }
        if(remainder==0){
            return powerOfTwo(quotient / 2, quotient % 2);
        } else {
            return powerOfTwo(remainder / 2, remainder % 2);
        }
    }

    public int[] findDisappearedNumbers (int[] nums) {
        // write code here
        if(nums==null){
            return nums;
        }
        int length = nums.length;
        int[] result;
        int[] data = new int[length];
        for (int i = 1; i <= data.length; i++) {
            data[i-1]=i;
        }
        ArrayList<Integer> filterData = new ArrayList<>();
        int[] array = Arrays.stream(nums).distinct().toArray();
        for (int j : array) {
            filterData.add(j);
        }
        if(length== array.length){
            return new int[0];
        } else {
            result=new int[length-array.length];
            int index = 0;
            for (int i : data) {
                if(!filterData.contains(i)){
                    result[index]=i;
                    index++;
                }
            }
        }
        return result;
    }
}
